package com.lxy.mychat1.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxy.mychat1.Bean.ChatItem;
import com.lxy.mychat1.Bean.User;
import com.lxy.mychat1.R;

import java.text.SimpleDateFormat;
import java.util.List;

public class ChatItemAdapter extends ArrayAdapter<ChatItem> {

    int resourceid;

    public ChatItemAdapter(@NonNull Context context, int resource, @NonNull List<ChatItem> objects) {
        super(context, resource, objects);
        this.resourceid = resource;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceid, null);
        }
        ImageView userimg = view.findViewById(R.id.userimg);
        TextView username = view.findViewById(R.id.username);
        TextView lastcontent = view.findViewById(R.id.lastcontent);
        TextView lastdate = view.findViewById(R.id.lastdate);
        ChatItem c = getItem(position);
        userimg.setImageResource(c.getUserimg());
        username.setText(c.getUsername());
        lastcontent.setText(c.getLastcontent());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String newdate = sdf.format(c.getLastdate());
        lastdate.setText(newdate);
        return view;
    }
}
